package com.hy.mydesktop.shared.util.log;


import java.util.Date;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;





public class MyGwtFormatter extends Formatter {
	
	Date dat = new Date();
	  private static final String format = "{0,date} {0,time}";
	  //private MessageFormat formatter;
	  private Object[] args = new Object[1];
	  //private String lineSeparator = (String)AccessController.doPrivileged(new GetPropertyAction("line.separator"));

	@Override
	public synchronized String format(LogRecord paramLogRecord) {
		
		StringBuffer localStringBuffer1 = new StringBuffer();
	    this.dat.setTime(paramLogRecord.getMillis());
	    this.args[0] = this.dat;
	    StringBuffer localStringBuffer2 = new StringBuffer();
	    
	    if (paramLogRecord.getLoggerName()!= null){
	    	localStringBuffer1.append("[");
	    	if ("".equals(paramLogRecord.getLoggerName())) {			
	    		localStringBuffer1.append("rootLogger");
			} else {
				localStringBuffer1.append(paramLogRecord.getLoggerName());
			}
	    	//System.err.println("loggerName :"+paramLogRecord.getLoggerName());	    	
	    	localStringBuffer1.append("]");
	    	
	    }
	    else{
	    	throw new RuntimeException("paramLogRecord.getLoggerName() is null! ");
	    }
	    localStringBuffer1.append(" ");
	    localStringBuffer1.append(DateTimeUtil.getCurrentMediumDateTime());//时间，如：2011-9-4 11:02:53
	    localStringBuffer1.append("\n");
	    String str = formatMessage(paramLogRecord);
    	localStringBuffer1.append(" <");
	    localStringBuffer1.append(paramLogRecord.getLevel());//Level如：信息、警告，错误
    	localStringBuffer1.append("> ");
	    //localStringBuffer1.append(": ");
	    localStringBuffer1.append(str);//格式化之后的message
	    //localStringBuffer1.append(this.lineSeparator);
	   
	     
	    return localStringBuffer1.toString();
	  }
	

	public MyGwtFormatter() {
		super();
		// TODO Auto-generated constructor stub
	}

}
